home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "defs.h"
-
- har *progname;
- har *filename;
- ixrect *pr;
-
- #ifdef STANDALONE
- ain(argc, argv, envp)
- #else
- as2array_main(argc, argv, envp)
- #endif
- int argc;
- char **argv;
- char **envp;
- {
- register int x, y;
- short *shortimage, *shortptr;
- unsigned char *charimage, *charptr;
- long *longimage, *longptr;
-
- progname = strsave(argv[0]);
- parse_profile(&argc, argv, envp);
-
- while ((gc = getopt(argc, argv, " ")) != EOF)
- switch (gc) {
- case '?':
- errflag++;
- break;
- }
-
- if (errflag)
- error((char *) 0, "Usage: %s: [infile] [outfile]\n", progname);
-
- for (stream = 0; optind < argc; stream++, optind++)
- if (stream < 2 && strcmp(argv[optind], "-") != 0)
- if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
- error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
-
- if ((pr = pr_load(stdin, NULL)) == NULL)
- error(PR_IO_ERR_RASREAD);
-
- switch (pr->pr_depth) {
- case 8:
- charimage = (unsigned char *) malloc(sizeof(unsigned char) * pr->pr_size.x);
- for (y = 0; y < pr->pr_size.y; y++) {
- charptr = charimage;
- for (x = 0; x < pr->pr_size.x; x++)
- *charptr++ = (char) pr_get(pr, x, y);
- if (fwrite(charimage, sizeof(*charimage), pr->pr_size.x, stdout) != pr->pr_size.x)
- error("Error writing image data (possible file size error)");
- }
- free(charimage);
- break;
- case 16:
- shortimage = (short *) malloc(sizeof(short) * pr->pr_size.x);
- for (y = 0; y < pr->pr_size.y; y++) {
- shortptr = shortimage;
- for (x = 0; x < pr->pr_size.x; x++)
- *shortptr++ = (short) pr_get(pr, x, y);
- if (fwrite(shortimage, sizeof(*shortimage), pr->pr_size.x, stdout) != pr->pr_size.x)
- error("Error writing image data (possible file size error)");
- }
- free(shortimage);
- break;
- case 24:
- error("Don't know how to write 24 bit images");
- break;
- case 32:
- longimage = (long *) malloc(sizeof(long) * pr->pr_size.x);
- for (y = 0; y < pr->pr_size.y; y++) {
- longptr = longimage;
- for (x = 0; x < pr->pr_size.x; x++)
- *longptr++ = (long) pr_get(pr, x, y);
- if (fwrite(longimage, sizeof(*longimage), pr->pr_size.x, stdout) != pr->pr_size.x)
- error("Error writing image data (possible file size error)");
- }
- free(longimage);
- break;
- }
- }
-